﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;

/// <summary>
/// Summary description for DAL_PhongKham
/// </summary>
public class DAL_ICD10 : SqlConnectionRun
{
	public DAL_ICD10()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    public DataTable TraCuuICD10(string MaBN, string MaICD)
    {
        string sqlselect = "";
        if (MaBN != "")
            sqlselect = "select VVIET,CICD10,vanh from PhongKham..ICD10 where VVIET like N'%" + MaBN + "%' order by CICD10 ";
        else if (MaICD != "")
            sqlselect = "select VVIET,CICD10,vanh from PhongKham..ICD10 where cicd10 like '%" + MaICD + "%' order by CICD10 ";
        else
            sqlselect = "select VVIET,CICD10,vanh from PhongKham..ICD10 order by CICD10 ";
        DataTable dt = SqlExecuteQueryReader(sqlselect);
        return dt;
    }

    public DataTable SearchICD10(string prefixText, int ReturnRows)
    {
        string SQL = "SELECT    Top "+ ReturnRows +" CICD10, VVIET" + "\n" +
                     "FROM      PhongKham..ICD10" + "\n" +
                     "WHERE     VVIET Like " + "N'%" + prefixText + "%'";
        DataTable dt = SqlExecuteQueryReader(SQL);
        return dt;
    }

    public DataTable LoadDanhMucICD()
    {
        string SQL = "SELECT    CICD10, VVIET" + "\n" +
                     "FROM      PhongKham..ICD10";                    
        DataTable dt = SqlExecuteQueryReader(SQL);
        return dt;
    }

    public int CapNhatICD10(string MaBN, string MaICD)
    {
        string updateQuery = "update icd10 set VVIET=N'" + MaBN + "' from PhongKham..ICD10 where cicd10 = '" + MaICD + "'";        
        return SqlExecuteNoneQuery(updateQuery);
    }

    public int ThemICD10(string MaBN, string MaICD)
    {
        string str = "insert into PhongKham..icd10(vviet, cicd10) values(N'" + MaBN + "',N'" + MaICD + "')";
        return SqlExecuteNoneQuery(str);
    }

    public int XoaICD10(string MaICD)
    {
        string str = "delete from icd10 where cicd10=N'" + MaICD + "'";
        return SqlExecuteNoneQuery(str);
    }
}